package cn.lblbc.webbrowser.utils

import android.content.Context
import android.content.SharedPreferences

class PasswordManager(context: Context) {
    private val prefs: SharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
    
    companion object {
        private const val PREFS_NAME = "password_prefs"
        private const val KEY_PASSWORD = "password"
        private const val DEFAULT_PASSWORD = "123456"
    }
    
    /**
     * 获取当前密码
     */
    fun getPassword(): String {
        return prefs.getString(KEY_PASSWORD, DEFAULT_PASSWORD) ?: DEFAULT_PASSWORD
    }
    
    /**
     * 设置新密码
     */
    fun setPassword(newPassword: String) {
        prefs.edit().putString(KEY_PASSWORD, newPassword).apply()
    }
    
    /**
     * 验证密码是否正确
     */
    fun verifyPassword(inputPassword: String): Boolean {
        return inputPassword == getPassword()
    }
}